package com.koron.sinoprobe.web.record.controller;

import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.sinoprobe.web.record.bean.SpRecord;
import com.koron.sinoprobe.web.record.service.SpRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "档案系统接口")
@RestController
@Slf4j
@RequestMapping("/sp/spRecord")
@CrossOrigin
public class SpRecordController {


    @Autowired
    private SpRecordService spRecordService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "查询档案管理系统组织结构")
    @GetMapping("/queryTree")
    public Response queryTree() {
        return spRecordService.queryTree();
    }

    @ApiOperation(value = "上传附件到档案管理系统")
    @PostMapping("/upload")
    public Response upload(@RequestBody SpRecord spRecord) {
        return spRecordService.upload(spRecord);
    }

    @ApiOperation(value = "保存文件索引")
    @PostMapping("/saveFileIndex")
    public Response saveFileIndex(String businessId, String indexs){
        return  ADOConnection.runTask(getCurrDs(), spRecordService, "saveFileIndex", Response.class, businessId, indexs);
    }

    @ApiOperation(value = "根据业务id查找文件索引")
    @GetMapping("/findFileIndexByBusinessId")
    public Response findFileIndexByBusinessId(String businessId){
        return  ADOConnection.runTask(getCurrDs(), spRecordService, "findFileIndexByBusinessId", Response.class, businessId);
    }

}
